define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'xeditor'], function ($, undefined, Backend, Table, Form) {
    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'merchant/ads/index',
                    add_url: 'merchant/ads/add',
                    edit_url: 'merchant/ads/edit',
                    del_url: 'merchant/ads/del',
                    multi_url: 'merchant/ads/multi',
                    table: 'ads',
                }
            });

            var table = $("#table");

            table.on('click', '.btn-hq', function(){
                let name = $(this).data('name');
                window.open('https://business.jxoxy.com/api/chamber_commerce/poster?name=' + name);
                return false;
            });

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id'), sortable: true},
                        {field: 'image', title: '图片地址', events: Table.api.events.image, formatter: Table.api.formatter.image, operate: false},
                        {field: 'url', title: '跳转地址', operate: 'LIKE'},
                        {field: 'type', title: '类型', searchList: window.typeListJson, formatter: function(value, row, index) {
                            return row.type_text;
                        }},
                        {field: 'odr', title: '排序'},
                        {field: 'status', title: '状态', searchList: window.statusListJson, formatter: function(value, row, index) {
                            return row.status_text;
                        }},
                        {field: 'createtime', title: '创建时间', events: Table.api.formatter.datetime,operate: 'RANGE', addclass: 'datetimerange', sortable: true},
                        {field: 'updatetime', title: '更新时间', events: Table.api.formatter.updatetime,operate: 'RANGE', addclass: 'datetimerange', sortable: true},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});